package nl.haemers
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import nl.haemers.base.BaseSprite;
	import nl.haemers.events.SpriteEvent;
	
	import nl.demonsters.debugger.MonsterDebugger;
	
	import nl.haemers.testrunners.*;
	import nl.haemers.utils.Logger;
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class Main extends Sprite 
	{
		public var debugger				:MonsterDebugger;
		public var bRunner				:BaseButtonRunner;
		public var stopWatchRunner		:StopWatchRunner;
		public var buttonRunner			:ButtonRunner;
		public var geomRunner			:GeomRunner;
		public var formRunner			:FormRunner;
		public var parseRunner			:XMLRunner;
		public var vRunner				:VideoRunner;
		public var collectionRunner		:CollectionRunner;
		public var objectRunner			:ObjectRunner;
		
		public var gRunner				:GridRunner;
		
		public function Main():void 
		{
			//Logger.getInstance().debugMode = false;
			Logger.i("start");
			if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			//debugger = new MonsterDebugger(this);
			//configListeners();
			
			//createCollectionRunner();
			createParseRunner();
			//createFormRunner();
			//createGeomRunner();
			//createButtonRunner();
			//createStopwatchRunner();
			//createBaseRunner();
			//createObjectRunner();
			//createGridRunner();
		}
		
		private function configListeners() : void
		{
			//stage.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		private function clickHandler(e:MouseEvent) : void
		{
			destroyRunner();
		}
		
		private function createObjectRunner() : void
		{
			objectRunner = new ObjectRunner();
			addChild(objectRunner);
		}
		
		private function createCollectionRunner() : void
		{
			collectionRunner = new CollectionRunner();
			addChild(collectionRunner);
		}
		
		private function createParseRunner() : void
		{
			parseRunner = new XMLRunner();
			addChild(parseRunner);
		}
		
		private function createFormRunner() : void
		{
			formRunner = new FormRunner();
			addChild(formRunner);
		}
		
		private function createGeomRunner() : void
		{
			geomRunner = new GeomRunner();
			addChild(geomRunner);
		}
		
		private function createButtonRunner() : void
		{
			buttonRunner = new ButtonRunner();
			buttonRunner.addEventListener(SpriteEvent.HIDE_COMPLETE, destroyRunner);
			addChild(buttonRunner);
		}
		
		private function createStopwatchRunner() : void
		{
			stopWatchRunner = new StopWatchRunner();
			addChild(stopWatchRunner);
			stopWatchRunner.start();
		}
		
		private function createBaseRunner() : void
		{
			bRunner = new BaseButtonRunner();
			addChild(bRunner);
			bRunner.start();
		}
		
		private function createVideoRunner() : void
		{
			vRunner = new VideoRunner();
			addChild(vRunner);
			//vRunner.start();
		}
		
		private function createGridRunner() : void
		{
			gRunner = new GridRunner();
			addChild(gRunner);
		}
		
		private function destroyRunner(e:SpriteEvent=null) : void
		{
			if (e.currentTarget)
			{
				var runner:BaseSprite = e.target as BaseSprite;
				runner.destroy();
				runner = null;
			}
		}
		
	}
	
}